package com.guojian.jdbc.jpa;

import javax.persistence.EntityManager;

import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.util.ClassTypeInformation;

//@Configuration
public class TestJpaRepository {

	/**
	 * SimpleJpaRepository 在jpa实现的基础上进行了相应的封装
	 * 1.必须使用jpa标准注解
	 * @param em
	 * @return
	 */
	//@Bean
	public SimpleJpaRepository<Test, String> getJpa(EntityManager em) {
		return new SimpleJpaRepository<>(Test.class, em);
	}

	/**
	 * 未实现jpa, 但是实现了对象转sql
	 * 1.可以直接操作对象来操作数据库
	 * 2.实体的注解必须使用spring的注解
	 * @param entityOperations
	 * @return
	 */
	//@Bean
	public SimpleJdbcRepository<Test, String> getJdbc(JdbcAggregateOperations entityOperations) {
		return new SimpleJdbcRepository<>(entityOperations, new BasicPersistentEntity<>(ClassTypeInformation.from(Test.class)));
	}

}
